package com.shangwu;

import java.io.*;

public class Test3 {
    public static void main(String[] args) {
//        File from = new File("D:\\java\\from");
//        File to = new File("D:\\java\\to");
//
//        File[] files = from.listFiles();
//        for(File f : files){
//            // 开启一个线程
//            new Thread(new Runnable() {
//                @Override
//                public void run() {
//                    try {
//                        BufferedInputStream bin = new BufferedInputStream(new FileInputStream(f));
//                        File fto = new File(to,f.getName());
//                        BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(fto));
//                        byte b[] = new byte[1024];
//                        int n = 0;
//                        while( (n=bin.read(b))!=-1 ){
//                            bout.write(b,0,n);
//                        }
//                        bout.close();
//                        bin.close();
//                    } catch (FileNotFoundException e) {
//                        e.printStackTrace();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }).start();
//
//        }


        File from = new File("D:\\java\\from");
        File to = new File("D:\\java\\to");

        File[] files = from.listFiles();
        for(File f : files){
            // 开启一个线程
            new Thread(()->{
                try {
                    BufferedInputStream bin = new BufferedInputStream(new FileInputStream(f));
                    File fto = new File(to,f.getName());
                    BufferedOutputStream bout = new BufferedOutputStream(new FileOutputStream(fto));
                    byte b[] = new byte[1024];
                    int n = 0;
                    while( (n=bin.read(b))!=-1 ){
                        bout.write(b,0,n);
                    }
                    bout.close();
                    bin.close();
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }).start();

        }



    }
}
